package com.Service;

import com.Dao.CategoryDao;
import com.POJO.Category;
import com.Service.Imp.CategoryServiceImp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class CategoryService extends ServiceImpl<CategoryDao, Category> implements CategoryServiceImp {
    @Autowired
    CategoryDao categoryDao;

    public List<Category> findAllCategory(){
        QueryWrapper<Category> categoryQueryWrapper=new QueryWrapper<>();
        return categoryDao.selectList(categoryQueryWrapper);
    }
    public int addCategory( String category1, String category2){
        Category category=new Category();
        category.setCategory1(category1);
        category.setCategory2(category2);
        return categoryDao.insert(category);
    }
    public int delCategory( String category1,String category2){
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("category1",category1);
        queryWrapper.eq("category2",category2);
        return categoryDao.delete(queryWrapper);
    }
    public int updataCategory( String category1,String category2,String newCategory1,String newCategory2){
        Category category=new Category();
        UpdateWrapper<Category> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("category1",newCategory1);
        updateWrapper.set("category2",newCategory2);
        updateWrapper.eq("category1",category1);
        updateWrapper.eq("category2",category2);
        return categoryDao.update(category,updateWrapper);
    }

}
